package ru.space.academy.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.space.academy.dto.JWTResponseDTO;
import ru.space.academy.dto.UserAuthDTO;
import ru.space.academy.dto.UserRegistrationDTO;
import ru.space.academy.service.AuthService;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("/registration")
    public ResponseEntity<Void> registerUser(@RequestBody UserRegistrationDTO regDTO) {
        authService.registerUser(regDTO);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PostMapping
    public ResponseEntity<JWTResponseDTO> registerUser(@RequestBody UserAuthDTO authDTO) {
        return new ResponseEntity<>(authService.auth(authDTO), HttpStatus.CREATED);
    }
}
